<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>垫款业务规则表 管理</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">规则名称</div>
                    <div class="field">
                        <input name="ruleNm" id="ruleNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>

                <div class="clearFix"></div>
                <div class="btnsBox">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                    <span id="addBtn" class="sq-button sq-button-round">新增</span>
                    <span id="addBtnManual" class="sq-button sq-button-round">手动新增</span>
                    <span id="changeBtn" class="sq-button sq-button-round">修改</span>
                    <span id="delBtn" class="sq-button sq-button-round">删除</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>
            </div>
        </form>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
    var grid = null,callback=null;
    $(function () {
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/capital/capAdvRuleInfo/initList.do',
            method: 'get',
            columns: [
                {display: '垫款规则名称', name: 'ruleNm', minWidth: 100, align: 'center', enabledSort: false},
		        //{display: '规则状态  1.开启 0.关闭', name: 'ruleStsCdNm', minWidth: 100, align: 'left', enabledSort: false},
		        {display: '垫款日期类型', name: 'dtTypCdNm', minWidth: 100, align: 'center', enabledSort: false},
		        {display: '垫款周期', name: 'advCycCdNm', minWidth: 100, align: 'left', enabledSort: false ,hide:true},
		        {display: '垫款时间', name: 'advTmCdNm', minWidth: 100, align: 'left', enabledSort: false,hide:true},
                {display: '垫款执行时间', minWidth: 120, align: 'center', enabledSort: false,
                    render:function(rowdata,index,value){
                        var h='';
                        if(rowdata.advCycCdNm != null && rowdata.advCycCdNm != '' && rowdata.advTmCdNm != null && rowdata.advTmCdNm != ''){
                            h +=rowdata.advCycCdNm+" "+rowdata.advTmCdNm;
                        }else if(rowdata.advCycCdNm != null && rowdata.advCycCdNm != ''){
                            h +=rowdata.advCycCdNm ;
                        }else if(rowdata.advTmCdNm != null && rowdata.advTmCdNm != ''){
                            h +=rowdata.advTmCdNm ;
                        }
                        return h ;
                    }
                },
		        {display: '垫款租金最小值', name: 'advMinAmt', minWidth: 100, align: 'left', enabledSort: false,hide:true},
		        {display: '垫款租金最大值', name: 'advMaxAmt', minWidth: 100, align: 'left', enabledSort: false,hide:true},
                {display: '垫款租金最小值', name: 'advMinAmtStr', minWidth: 100, align: 'left', enabledSort: false,hide:true},
                {display: '垫款租金最大值', name: 'advMaxAmtStr', minWidth: 100, align: 'left', enabledSort: false,hide:true},
                {display: '逾期金额', minWidth: 200, align: 'center', enabledSort: false,
                    render:function(rowdata,index,value){
                        var h = '';
                        if(rowdata.advMinAmt != null && rowdata.advMinAmt != '' && (rowdata.advMaxAmt == null || rowdata.advMaxAmt == '')){
                            h += '>='+rowdata.advMinAmtStr;
                        }else if(rowdata.advMinAmt != null && rowdata.advMinAmt != ''){
                            h += rowdata.advMinAmtStr;
                        }
                        if(rowdata.advMinAmt != null && rowdata.advMinAmt != '' && rowdata.advMaxAmt != null && rowdata.advMaxAmt != ''){
                            h += '~';
                        }
                        if(rowdata.advMaxAmt != null && rowdata.advMaxAmt != '' && (rowdata.advMinAmt == null || rowdata.advMinAmt == '')){
                            h += '<='+rowdata.advMaxAmtStr;
                        }else if(rowdata.advMaxAmt != null && rowdata.advMaxAmt != ''){
                            h += rowdata.advMaxAmtStr;
                        }
                        return h;
                    }
                },
		        {display: '逾期起始天数', name: 'minOvdDay', minWidth: 100, align: 'left', enabledSort: false,hide:true},
		        {display: '逾期截止天数', name: 'maxOvdDay', minWidth: 100, align: 'left', enabledSort: false,hide:true},
                {display: '逾期天数', minWidth: 100, align: 'center', enabledSort: false,
                    render:function(rowdata,index,value){
                        var h = '';
                        if(rowdata.minOvdDay != null && rowdata.minOvdDay != '' && (rowdata.maxOvdDay == null || rowdata.maxOvdDay == '')){
                            h += '>='+rowdata.minOvdDay;
                        }else if(rowdata.minOvdDay != null && rowdata.minOvdDay != ''){
                            h += rowdata.minOvdDay;
                        }
                        if(rowdata.minOvdDay != null && rowdata.minOvdDay != '' && rowdata.maxOvdDay != null && rowdata.maxOvdDay != ''){
                            h += '~';
                        }
                        if(rowdata.maxOvdDay != null && rowdata.maxOvdDay != '' && (rowdata.minOvdDay == null || rowdata.minOvdDay == '')){
                            h += '<='+rowdata.maxOvdDay;
                        }else if(rowdata.maxOvdDay != null && rowdata.maxOvdDay != ''){
                            h += rowdata.maxOvdDay;
                        }
                        return h;
                    }
                },
                {display: '垫款基数', name: 'advBaseCdNm', minWidth: 100, align: 'center', enabledSort: false},
                {display: '垫款颗粒度', name: 'advTypCdNm', minWidth: 100, align: 'center', enabledSort: false},
                {display: '垫款期数', name: 'advPd', minWidth: 100, align: 'center', enabledSort: false},
                {display: '状态', name: 'isValid', minWidth: 100, align: 'center', enabledSort: false,
                    render:function(rowdata,index,value){
                        if(rowdata.isValid == '1'){
                            return '有效';
                        }else{
                            return '无效';
                        }
                    }
                },
		        {display: '垫款方式', name: 'isAllAdv', minWidth: 100, align: 'center', enabledSort: false,
                    render:function(rowdata,index,value){
                        if(rowdata.isAllAdv == '1'){
                            return '全垫';
                        }else{
                            return '非全垫';//rowdata.advPd + '期';
                        }
                    }
                },
                {
                    display: '启用状态', width: 100, align: 'center', enabledSort: false,
                    render: function (rowdata, index, value) {
                        /*if(rowdata.ruleStsCd == '1'){
                            return '<input type="radio" name="ruleStsCd_\''+index+'\'" id="ruleStsCd_\''+index+'\'" checked /><span class="requiredSymbol">开启</span>' + '<input type="radio" name="ruleStsCd_\''+index+'\'" id="ruleStsCd_\''+index+'\'" /><span class="requiredSymbol">关闭</span>';
                        }
                        return  '<input type="radio" name="ruleStsCd_\''+index+'\'" id="ruleStsCd_\''+index+'\'" /><span class="requiredSymbol">开启</span>'+'<input type="radio" name="ruleStsCd_\''+index+'\'" id="ruleStsCd_\''+index+'\'" checked /><span class="requiredSymbol">关闭</span>';*/
                        if(rowdata.ruleStsCd == '1'){
                            return '<a href="javascript:changeRuleStsCd('+rowdata.id+',\''+rowdata.ruleStsCd+'\');" class="link"><span class="requiredSymbol">已开启</span></a>';
                         }
                            return '<a href="javascript:changeRuleStsCd('+rowdata.id+',\''+rowdata.ruleStsCd+'\');" class="link"><span class="requiredSymbol">已关闭</span></a>';
                    }
                }
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            //isScroll: false,
            checkbox: true,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false
            /* onRenderComplete: function () {
             iframeResize ();
             } */
        });
        grid.setHeight(100);

        $("#searchBar").ligerForm();

        $("#pageloading").hide();


        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            clearLigerForm("searchBar");
        });
        
        callback = function () {
            grid.reload();
        };

        /* 新增 */
        $("#addBtn").click(function (event) {
            $.ligerDialog.open({
                width: 650,
                height: 600,
                title: '新增垫款业务规则表',
                url:'<%=path%>/capital/capAdvRuleInfo/toAddPage.do'
            });
            //Add_navTab("CapAdvRuleInfo_1", "新增垫款业务规则表", '<%=path%>/capital/capAdvRuleInfo/toAddPage.do', callback);
        });

        /* 手动新增 */
        $("#addBtnManual").click(function (event) {
            $.ligerDialog.open({
                width: 800,
                height: 650,
                title: '新增垫款业务规则表',
                url:'<%=path%>/capital/capAdvRuleInfo/toAddPage.do?ruleTypCd=2'
            });
            //Add_navTab("CapAdvRuleInfo_1", "新增垫款业务规则表", '<%=path%>/capital/capAdvRuleInfo/toAddPage.do', callback);
        });

        /* 修改 */
        $("#changeBtn").click(function (event) {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length != 1) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            var _id=selectedRows[0].id;
            $.ligerDialog.open({
                width: 650,
                height: 600,
                title: '修改垫款业务规则表',
                url:'<%=path%>/capital/capAdvRuleInfo/toModifyPage.do?id='+_id
            });
            //Add_navTab('CapAdvRuleInfo_2'+_id, "修改垫款业务规则表", '<%=path%>/capital/capAdvRuleInfo/toModifyPage.do?id='+_id, callback);
        });

        /* 删除 */
        $("#delBtn").click(function () {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length == 0) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
                return;
            }
            var _ids = [];
            for (var index in selectedRows) {
                _ids.push(selectedRows[index].id);
            }

            $.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
                if (flag == false)return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {ids: JSON.stringify(_ids)},
                    url: '<%=path%>/capital/capAdvRuleInfo/removeByIds.do',
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({
                            content: LogUtils.LOG_CMM_DATA_LOADING,
                            SQ_type: "waitting"
                        });
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                            grid.reload();
                        } else {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
        });

    });

    function changeRuleStsCd(id,ruleStsCd){
        if(null == id || '' == id ){
            $.ligerDialog.SQalert({content: "数据主键ID不能为空！", SQ_type: "error"});
            return ;
        }
        if(ruleStsCd == '1'){
            ruleStsCd = '0';
        }else{
            ruleStsCd = '1';
        }
        $.ligerDialog.confirm(ruleStsCd == '1' ? LogUtils.LOG_CMM_ENABLE_CONFIRM :LogUtils.LOG_CMM_DISABLE_CONFIRM, function (flag) {
            if (flag == false)return;
            $.ajax({
                type: 'get',
                dataType: 'json',
                url: '<%=path%>/capital/capAdvRuleInfo/modify.do?id='+id+'&ruleStsCd='+ruleStsCd,
                success: function (msg) {
                    if (msg.success == 1) {
                        grid.reload();
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    }
</script>

</body>
</html>
